import java.util.Objects;

/**
 * @author zhangshuai
 * @version V1.0
 * @Project Java2_26
 * @Package PACKAGE_NAME
 * @Description:
 * @Date 2025/5/14 17:20
 */

public class Demo3 {

    //基本类型 ==  值
    //引用类型 == 地址
    // equals 比较引用类型  原本是比较是否是同一个地址，但是在业务中，比较值是否相等
    public static void main(String[] args) {
        Student student1 = new Student(18, "张三");
        Student student2 = new Student(18, "张三");
        System.out.println(student1);
        System.out.println(student2);
        System.out.println(student1 == student2); //false
        System.out.println(student1.equals(student2)); //true
    }

}
class Student{
    private int age;
    private String name;

    public Student(int age, String name) {
        this.age = age;
        this.name = name;
    }
    //重写equals
    @Override
    public boolean equals(Object o) {
        // 判断当前对象是否与传入的对象相等
         if (this == o) return true;
         // 判断传入的对象是否为空或者当前对象的类是否与传入对象的类不相等
         if (o == null || getClass() != o.getClass()) return false;
         // 将传入的对象转换为Student类型
         Student student = (Student) o;
         // 判断当前对象的年龄是否与传入对象的年龄相等，并且当前对象的名字是否与传入对象的名字相等
         return age == student.age && name.equals(student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name);
    }
}